import urllib.request

url = 'https://www.baidu.com'

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36'
}
# 定制请求对象，模拟浏览器的UA
request = urllib.request.Request(url=url,headers=headers)
# 传递请求对象进行请求
response = urllib.request.urlopen(request)

content = response.read().decode('utf8')
print(content)
